package com.ruoyi.member.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.member.domain.BmInordergoodslist;
import com.ruoyi.member.domain.BmInorderlist;
import com.ruoyi.member.domain.BmSpecification;
import com.ruoyi.member.domain.vo.SalesOrder;
import com.ruoyi.member.service.IBmInordergoodslistService;
import com.ruoyi.member.service.IBmInorderlistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * #销售单管理Controller
 *
 * @author ruoyi
 * @date 2023-08-03
 */
@RestController
@RequestMapping("/inorderlist")
public class BmInorderlistController extends BaseController
{
    @Autowired
    private IBmInorderlistService bmInorderlistService;
    @Autowired
    private IBmInordergoodslistService bmInordergoodslistService;


    /**
     * 获取#订单详情信息详细信息
     */
    @GetMapping(value = "/goods/{orderCode}")
    public TableDataInfo getInordergoodsOne(@PathVariable("orderCode") Long orderCode)
    {
        startPage();
        List<BmInordergoodslist> bmInordergoodslists = bmInordergoodslistService.selectBmInordergoodslistById(orderCode);
        return getDataTable(bmInordergoodslists);
    }
    /**
     * 查询#销售单管理列表
     */
    @GetMapping("/list")
    public TableDataInfo getSalesOrder(SalesOrder salesOrder)
    {
        startPage();
        List<SalesOrder> list = bmInorderlistService.getSalesOrder(salesOrder);
        for (SalesOrder order : list) {
            order.setAddress(order.getMainAddress()+order.getAddress());
            order.setTrueName(order.getTrueName()+","+order.getBusinessName());
        }
        return getDataTable(list);
    }

    /**
     * 导出#销售单管理列表
     */
    @RequiresPermissions("member:inorderlist:export")
    @Log(title = "#销售单管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BmInorderlist bmInorderlist)
    {
        List<BmInorderlist> list = bmInorderlistService.selectBmInorderlistList(bmInorderlist);
        ExcelUtil<BmInorderlist> util = new ExcelUtil<BmInorderlist>(BmInorderlist.class);
        util.exportExcel(response, list, "#销售单管理数据");
    }

    /**
     * 获取#销售单管理详细信息
     */
    @RequiresPermissions("member:inorderlist:query")
    @GetMapping(value = "order/{orderCode}")
    public AjaxResult getInfo(@PathVariable("orderCode") String orderCode)
    {
        SalesOrder bmInorder = bmInorderlistService.selectBmInorderlistByOrderCode(orderCode);
        bmInorder.setAllMoney(bmInorder.getAmount().doubleValue()+bmInorder.getDeliveryFee().doubleValue());
        bmInorder.setAddress(bmInorder.getMainAddress()+bmInorder.getAddress());
        return AjaxResult.success(bmInorder);
    }

    /**
     * 新增#销售单管理
     */
    @RequiresPermissions("member:inorderlist:add")
    @Log(title = "#销售单管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody BmInorderlist bmInorderlist)
    {
        return toAjax(bmInorderlistService.insertBmInorderlist(bmInorderlist));
    }

    /**
     * 修改#销售单管理
     */
    @RequiresPermissions("member:inorderlist:edit")
    @Log(title = "#销售单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BmInorderlist bmInorderlist)
    {
        return toAjax(bmInorderlistService.updateBmInorderlist(bmInorderlist));
    }

    /**
     * 删除#销售单管理
     */
    @RequiresPermissions("member:inorderlist:remove")
    @Log(title = "#销售单管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderCodes}")
    public AjaxResult remove(@PathVariable String[] orderCodes)
    {
        return toAjax(bmInorderlistService.deleteBmInorderlistByOrderCodes(orderCodes));
    }

    /**
     * 修改商品库存
     */
    @PostMapping("/changeGoodsStock")
    public AjaxResult changeGoodsStock(@RequestBody BmSpecification bmSpecification)
    {
       bmSpecification.setStock(bmSpecification.getBuyNum());
       bmSpecification.setId(bmSpecification.getSpecificationId());
        return toAjax(bmInordergoodslistService.changeGoodsStock(bmSpecification));
    }

    @GetMapping(value = "ordersteptotwo/{orderCode}")
    public AjaxResult updateOrderStepToTwo(@PathVariable("orderCode") String orderCode)
    {
        return toAjax(bmInorderlistService.updateOrderStepToTwo(orderCode));
    }

    @GetMapping(value = "ordersteptothree/{orderCode}")
    public AjaxResult updateOrderStepToThree(@PathVariable("orderCode") String orderCode)
    {
        return toAjax(bmInorderlistService.updateOrderStepToThree(orderCode));
    }

    @GetMapping(value = "ordersteptofour/{orderCode}")
    public AjaxResult updateOrderStepToFour(@PathVariable("orderCode") String orderCode)
    {
        return toAjax(bmInorderlistService.updateOrderStepToFour(orderCode));
    }
    @GetMapping(value = "ordersteptofive/{orderCode}")
    public AjaxResult updateOrderStepToFive(@PathVariable("orderCode") String orderCode)
    {
        return toAjax(bmInorderlistService.updateOrderStepToFive(orderCode));
    }
    @GetMapping(value = "ordersteptosix/{orderCode}")
    public AjaxResult updateOrderStepToSix(@PathVariable("orderCode") String orderCode)
    {
        return toAjax(bmInorderlistService.updateOrderStepToSix(orderCode));
    }
    @GetMapping(value = "ordersteptoseven/{orderCode}")
    public AjaxResult updateOrderStepToSeven(@PathVariable("orderCode") String orderCode)
    {
        return toAjax(bmInorderlistService.updateOrderStepToSeven(orderCode));
    }

}
